<template>
  <div class="app-container">
    <el-card class="box-card">
      <el-form ref="form" :model="form" >
        <el-descriptions title="需求信息" style="text-align: center" :column="2" border >
          <el-descriptions-item :contentStyle="contentStyle"label="需求名称" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.resultName}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="需求类别" :span="1" label-class-name="my-label" :labelStyle="labelStyle" >
            <dict-tag :options="dict.type.cxcy_result_category" :value="form.resultCategory"/></el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle"label="需求人姓名" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.firstName}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="技术领域" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            <dict-tag :options="dict.type.cxcy_technology" :value="form.technology"/></el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="成果简介" :span="2"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.resultIntroduction}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="创新点" :span="2"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.innovationPoint}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="成果研究意义" :span="2"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.resultMeaning}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="附件" :span="2"  label-class-name="my-label" :labelStyle="labelStyle" >
            <el-button @click="hadledownload">下载</el-button></el-descriptions-item>
        </el-descriptions>
        <br/>
        <el-descriptions title="申请人员信息" style="text-align: center" :column="2" border >
          <el-descriptions-item :contentStyle="contentStyle"label="需求人姓名" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.firstName}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="法人姓名" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.corporateName}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="法人邮箱" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.corporateEmail}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="法人电话" :span="1" label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.corporatePhone}}</el-descriptions-item>
<!--          <el-descriptions-item :contentStyle="contentStyle" label="地图条码" :span="1" label-class-name="my-label" :labelStyle="labelStyle" >-->
<!--            <el-button @click="hadledownload">下载</el-button></el-descriptions-item>-->
        </el-descriptions>
        <br/>
        <el-descriptions title="企业信息" style="text-align: center" :column="2" border >
          <el-descriptions-item :contentStyle="contentStyle"label="企业名称" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.enterpriseName}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="统一社会信用代码" :span="1"  label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.enterpriseNumber}}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="企业地址" :span="1" label-class-name="my-label" :labelStyle="labelStyle" >
            {{form.enterpriseAddress}}</el-descriptions-item>
        </el-descriptions>
        <br/>
        <el-descriptions  title="审核信息" style="text-align: center" :column="2" border >
          <el-descriptions-item :contentStyle="contentStyle" label="审核状态" :span="1" label-class-name="my-label" :labelStyle="labelStyle" >
            <dict-tag :options="dict.type.cxcy_audit_status" :value="form.auditState"/></el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="审核时间" :span="1" label-class-name="my-label" :labelStyle="labelStyle" >
            {{ form.auditTime }}</el-descriptions-item>
          <el-descriptions-item :contentStyle="contentStyle" label="审核人姓名" :span="1" label-class-name="my-label" :labelStyle="labelStyle" >
            {{ form.auditName }}</el-descriptions-item>

        </el-descriptions>

      </el-form>
      <br/>
      <div style="float:right; margin-bottom: 15px;">
        <el-button @click="viewCancel">返 回</el-button>
      </div>
    </el-card>
  </div>
</template>
<script>

import {getDemand} from "@/api/module/lys/demand";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import watermark from "watermark-dom";
export default {
  name: "detail",
  dicts: ['cxcy_result_category', 'cxcy_audit_status','cxcy_technology'],
  data() {
    return {
      contentStyle:{
        'width':'200px'
      },
      form:{},
      labelStyle: { 'width': '12%','color': '#000000','text-align': 'right', },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 部门树选项
      deptOptions: undefined,
      // 合同资料表格数据
      fileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
    };
  },
  mounted() {
    watermark.load({ watermark_txt: "  "   });
  },
  created() {
    const id = this.$route.query.id;
    if (id) {
      // 获取表详细信息

      getDemand(id).then(res => {

        this.form = res.data;
      });

    }
  },
  methods: {

    hadledownload(){
      /*const materialsAddress = this.form.materialsAddress;

            window.open(materialsAddress);
    */
// 默认方法
      const note10 = this.form.note10;

      const xhr = new XMLHttpRequest();
      xhr.open('GET', note10, true);
      xhr.responseType = 'blob';
      xhr.setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
      xhr.onload = function () {
        if (xhr.status === 200) {
          const contentType = xhr.response.type;
          const contentDisposition = xhr.getResponseHeader('Content-Disposition');
          let fileName = '';

          if (contentDisposition) {
            const fileNameMatch = contentDisposition.match(/filename="(.*?)"/);
            if (fileNameMatch.length > 1) {
              fileName = fileNameMatch[1];
            }
          }

          if (!fileName) {
            // 如果从响应头中没有解析出文件名，则从 URL 中获取文件名
            const urlSplit = note10.split('/');
            fileName = urlSplit[urlSplit.length - 1];
          }

          saveAs(xhr.response, fileName);
        } else {
          console.error('文件下载失败');
        }
      };
      xhr.send();


    },
    /** 关闭按钮 */
    viewCancel() {
      const id = this.$route.query.id;
      getDemand(id).then(response => {
        this.form = response.data;
      });
      const obj = { path: "/qiyexuqiu/xuqiuchakan", query: {id} };
      this.$tab.closeOpenPage(obj);
    }
  },
};
</script>








